package com.fingard.dsp.bank.directbank.fxb01.util;

import cn.highsuccess.connPool.api.tssc.HisuTSSCAPI;
import cn.highsuccess.connPool.api.tssc.HisuTSSCAPIResult;

/**
 * @Description TODO
 * @Author xtt
 **/
public class MACUtil {

    public static String getMAC(String reqStr,String designID,String nodeID,String keyModelID,String configFile){
        HisuTSSCAPIResult tsscRet = new HisuTSSCAPIResult();
        HisuTSSCAPI tsscObj = new HisuTSSCAPI(configFile , "QYGL");
        String MAC = "";
        try {
            byte[] arbyte = reqStr.getBytes();
            //参数（1.密钥方案标识 2.密钥节点标识 3.工作密钥模板标识（密钥标识：RZAK） 4.0：RTAK1：RZAK(固定值1) 5.1：SHA1 2：SM3 6.二进制表示的输入数据 7.二进制表示的输入数据的长度）
            tsscRet = tsscObj.calculateHashDataMACBySpecKeyBytes(designID,nodeID,keyModelID,  1, 2, arbyte, arbyte.length);
            MAC = tsscRet.getMAC();
            MAC = designID + "|" + nodeID +"|" + keyModelID + "|" + MAC;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return "";
        }
        if (tsscRet.getErrCode() < 0) {
            System.out.println("MAC签名失败：状态码：" + tsscRet.getErrCode() + "状态信息：" +  tsscRet.getErrMsg());
            return "";
        }
        return MAC;
    }
}
